// File Name: UIAutomationCPP.h

#ifndef UIAUTOMATIONCPP_H
#define UIAUTOMATIONCPP_H

#include <UIAutomation.h>

#include "Stdafx.h"
#include "CustomUIAutomationCPP.h"
#include "RotatePatternHandler.h"
#include "IClientWrapper.h"
#include "ServerSideCustomProvider.h"
#include "RotateClientSideCustomProvider.h"

using namespace System;

namespace UIAutomationCPP
{
	static RotatePatternHandler handlerInfo;

	static GUID valuePropertyGuid = { 0xb7c92a75, 0xfe41, 0x4916, { 0x90, 0x54, 0x33, 0xac, 0x33, 0x5d, 0xfb, 0x68 } };
	static GUID isReadOnlyPropertyGuid = { 0x412fe18c, 0x570d, 0x44a6, { 0x9b, 0xcc, 0x2c, 0xb4, 0x72, 0x9, 0xa3, 0xeb } };
	static GUID eventGuid = { 0xca66d626, 0x2e0d, 0x437c, { 0xb9, 0xb0, 0xd4, 0x97, 0x1b, 0x8b, 0x46, 0x7e } };
	static GUID methodGuid = { 0x6952d72a, 0xb39b, 0x4ce2, { 0xb5, 0x21, 0xa2, 0x2f, 0xc4, 0x43, 0xdb, 0xd9 } };
	static GUID patternGuid = { 0xd47a0b8d, 0x4866, 0x468f, { 0xa3, 0x4c, 0x13, 0x2e, 0x3d, 0x8b, 0xfd, 0xba } };

	enum RotateEnum
	{
		Rotation_GetIsReadOnly = 0,
		Rotation_GetValue = 1,
		Rotation_SetValue = 2,
		Rotation_Reset = 3,
	};

	static UIAutomationType UiaStringType[] = { UIAutomationType_String };
	static LPCWSTR rotateMethod[] = { L"RotationPattern.SetValue" };

	static UIAutomationPropertyInfo propertyInfo[] = { { isReadOnlyPropertyGuid, L"RotationPattern.IsReadOnly", UIAutomationType_Bool },
														{ valuePropertyGuid, L"RotationPattern.Value", UIAutomationType_String } };
	static UIAutomationEventInfo eventInfo[] = { { eventGuid, L"RotationPattern.Reset" } };
	static UIAutomationMethodInfo methodInfo[] = { /*{ L"RotationPattern.Rotate", TRUE, 1, 0, UiaStringType, rotateMethod }, */{ L"RotationPattern.Reset", TRUE, 0, 0, NULL, NULL } };
	static UIAutomationPatternInfo patternInfo = {  patternGuid, L"RotationPattern",
													__uuidof(ICustomProvider), __uuidof(IClientWrapper),
													(sizeof propertyInfo)/sizeof(UIAutomationPropertyInfo), propertyInfo,
													(sizeof methodInfo)/sizeof(UIAutomationMethodInfo), methodInfo,
													(sizeof eventInfo)/sizeof(UIAutomationEventInfo), eventInfo,
													&handlerInfo};

	static int* proid1;
	static int* proid2;

	public ref class ManagedRotateWrapper
	{
		public:
			ManagedRotateWrapper(){ customUIA = new CustomUIAutomationCPP(); }
			//~ManagedRotateWrapper(){ delete [] customUIA; }
			CustomUIAutomationCPP* customUIA;

			int readonlyid;
			int valueid;
			int eventid;
			int patternid;
			int controlid;

			int RegisterRotateProperty(){ return (*customUIA).RegisterRotateProperty(); }
			int RegisterRotateEvent(){ return (*customUIA).RegisterRotateEvent(); }
			int RegisterRotatePattern(){ int ret = (*customUIA).RegisterRotatePattern(); readonlyid = Rotate_IsReadOnly_PropertyID; valueid = Rotate_Value_PropertyID; eventid = Rotate_Reset_EventID; return ret; }
			//void SetGlobalValues(){ Rotate_Value_PropertyID = valueid; Rotate_IsReadOnly_PropertyID = readonlyid; Rotate_Reset_EventID = eventid; Rotate_PatternID = patternid; }
	};

	public ref class ManagedServerProvider
	{
		public:
			ManagedServerProvider(){ provider = new ServerSideCustomProvider(); }
			ServerSideCustomProvider* provider;
	};

	public ref class ManagedClientProvider
	{
		public:
			//ManagedClientProvider(){ provider = new RotateClientSideCustomProvider(); }
			ManagedClientProvider(IntPtr owner){ provider = new RotateClientSideCustomProvider((HWND)owner.ToPointer()); }
			RotateClientSideCustomProvider* provider;
	};

	template <class T>
	void SafeRelease(T **ppT)
	{
		if (*ppT)
		{
			(*ppT)->Release();
			*ppT = NULL;
		}
	}
}
#endif
